# set={1,2,3,4,5,6,7,8,9,10}
# myset=set()
# print(myset)
# print(set)
# 去重
# 无序性，唯一性
my_set={"教育","itheima","itcast","教育","itheima","itcast"}
my_set_mpty=set()
print(f"my_set的内容是{my_set}类型是{type(my_set)}")
print(f"my_set_mpty的内容是{my_set_mpty},类型是{type(my_set)}")

# 添加新元素
my_set.add("Python")
my_set.add("教育")
print(f"my_set添加新元素后结果是{my_set}")
# 移除元素
my_set.remove("教育")
print(f"my_set移除新元素后结果是{my_set}")
# 随机取出
my_set={"教育","itheima","itcast","教育","itheima","itcast"}
element=my_set.pop()
print(f"集合被取出的元素是{element},取出元素后还有{my_set}")
# 清空集合
my_set.clear();
print(f"集合被清空了,结果是{my_set}")
# 取两个集合的差集
set1={1,2,3,4,5}
set2={1,2,4,7,8,9}
set3=set1.difference(set2)#集合一有集合二没有
print(f"取出的差集:{set3}")
print(f"取出差集前原有set2:{set2}")
print(f"取出差集前原有set2:{set1}")
# 消除两个集合的差集
# 在集合一内删除集合二相同的元素
set1 = {1,2,3,4,5}
set2={1,5,6}
set1.difference_update(set2)
print(f"消除差集后set3的集合为:{set1}")
print(f"消除差集后set2的集合为:{set2}")

# 集合合并
set1 = {1,2,3}
set2 = {1,5,6}
set3=set1.union(set2)
print(f"合并后的结果是{set3}")

# 统计集合的元素
set1 = {1,2,3,4,5}
set2 = {1,5,6}
numbers = len(set1)
print(f"集合内的元素个数是{numbers}")

# 集合的遍历
set1 = {1,2,3,4,5}
for e in set1:
    print(f"集合的元素有{e}个")
